import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { produce } from "immer";
export type pageInfoStateType = {
  title: string;
  desc: string;
  js: string;
  css: string;
  isPublish: boolean;
};

const initState: pageInfoStateType = {
  title: "页面标题",
  desc: "页面描述",
  js: "",
  css: "",
  isPublish: false,
};

const pageInfoSlice = createSlice({
  name: "pageInfoSlice",
  initialState: initState,
  reducers: {
    resetPageInfo(state: pageInfoStateType, action: PayloadAction<pageInfoStateType>) {
      return action.payload;
    },
    changePageInfoTtle: produce((draft: pageInfoStateType, action: PayloadAction<string>) => {
      const title = action.payload;
      draft.title = title;
    }),
  },
});

export const { resetPageInfo, changePageInfoTtle } = pageInfoSlice.actions;

export default pageInfoSlice.reducer;
